<?php

namespace Modules\Openapi\Middlewares;

use App\Exceptions\MemberForbiddenException;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

/**
 * 判断用户是否被禁用
 */
class CheckUserStateMiddleware
{
    /**
     * @param Request $request
     * @param Closure $next
     * @param string  $guard
     * @return mixed
     */
    public function handle(Request $request, Closure $next, string $guard)
    {
        $user = Auth::guard($guard)->user();
        if ($user && isset($user->status) && $user->status != 1) {
            throw new MemberForbiddenException();
        }

        return $next($request);
    }
}
